
import { Controller, Post, Body, SetMetadata } from '@nestjs/common';
import { BaseDao } from '@/common/baseDao/base.service';
import { Util } from '@/common/util/util.service';
@SetMetadata('isLogger', true)
@Controller()
export class SystemUserController {

    constructor(
        private baseDao: BaseDao,
        private util: Util,
    ) { }


    @Post('/getList')
    async getList(@Body() data) {
        const { _ } = this.util;
        return await this.baseDao.getTableData({
            dbName: 'quick-users',
            data,
            whereJson: {
                role: _.exists(true)
            },
        })
    }

    @Post('/add')
    async add(@Body() data) {
        return await this.baseDao.add({
            dbName: 'quick-users',
            dataJson: data
        })
    }

    @Post('/update')
    update(@Body() data) {
        console.log('data', data)
        const {
            _id,
            username,
            _add_time,
            no,
            gender,
            status,
            role,
            higher_up_id,
            higher_up_username
        } = data;
        return this.baseDao.updateById({
            id: _id,
            dbName: 'quick-users',
            dataJson: {
                username,
                _add_time,
                no,
                gender,
                status,
                role,
                higher_up_id,
                higher_up_username
            }
        })
    }

    @Post('/delete')
    async delete(@Body() data) {
        console.log('data', data)
        return await this.baseDao.del({
            dbName: 'quick-users',
            whereJson: data
        })
    }
}